package com.voice.server.command.impl;

import com.voice.server.command.DeviceCommand;
import com.voice.server.connection.ConnectionInvoke;
import com.voice.server.message.device.FileMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;

@Component
public class AudioFileCommand implements DeviceCommand<InputStream> {

    private String topic="/device/file";
    @Autowired
    private ConnectionInvoke connectionInvoke;

    @Override
    public void execute(String userId, String deviceKey, InputStream inputStream) {
        try {
            FileMessage fileMessage=new FileMessage(inputStream);
            connectionInvoke.sendDeviceMessage(deviceKey,topic,fileMessage);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
